{include 'admin/layout/header_list'}
<link rel="stylesheet" href="__ADMIN_STATIC__/css/addContent.css?random={extendSetting('random')}">
<div class="addcontent">
    <form class="ajaxForm" method="post" >
        <input type="hidden" name="_method" value="put" >
        <input type="hidden" name="id" value="{if isset($rowData['id'])}{$rowData['id']}{/if}" >
        <input type="hidden" name="moduleId" value="{if isset($request['moduleId'])}{$request['moduleId']}{/if}" >
        <table class="switchContainer table" >
            <tbody class="tb">
            <tr>
                <td class="tl">
                    <span><strong>* </strong>字段</span>
                </td>
                <td>
                    <input class="short" name="name" type="text" value="{if isset($rowData['name'])}{$rowData['name']}{/if}" >小写字母(a-z),数字(0-9) 推荐使用字母,不能以数字开头
                </td>
            </tr>
            <tr>
                <td class="tl">
                    <span><strong>* </strong>字段名称</span>
                </td>
                <td>
                    <input class="short" type="text" name="title" value="{if isset($rowData['title'])}{$rowData['title']}{/if}" >
                </td>
            </tr>
            <tr>
                <td class="tl">
                    <span> 提示信息</span>
                </td>
                <td>
                    <input class="long" type="text" name="note" value="{if isset($rowData['note'])}{$rowData['note']}{/if}" >
                </td>
            </tr>
            <tr>
                <td class="tl">
                    <span><strong>* </strong> 字段属性</span>
                </td>
                <td>
                    <select name="type" class="short" onchange="changeType(this)">
                        <option value="varchar" {if isset($rowData['type']) && $rowData['type']=='varchar'}selected{/if} >字符(Varchar)</option>
                        <option value="int" {if isset($rowData['type']) && $rowData['type']=='int'}selected{/if} >整数(Int)</option>
                        <option value="float" {if isset($rowData['type']) && $rowData['type']=='float'}selected{/if} >小数(Float)</option>
                        <option value="text" {if isset($rowData['type']) && $rowData['type']=='text'}selected{/if} >文本(Text)</option>
                    </select>
                </td>
            </tr>
            <tr id="tr_length" >
                <td class="tl">
                    <span> 字段长度</span>
                </td>
                <td>
                    <input class="short" type="text" name="length" value="{if isset($rowData['length'])}{$rowData['length']}{/if}">建议使用中文
                </td>
            </tr>
            <tr>
                <td class="tl">
                    <span><strong>* </strong> 表单类型</span>
                </td>
                <td>
                    <select name="html" class="short" onchange="changeHtml(this)" >
                        <option value="text" {if isset($rowData['html']) && $rowData['html']=='text'}selected{/if} >单行文本(text)</option>
                        <option value="textarea" {if isset($rowData['html']) && $rowData['html']=='textarea'}selected{/if} >多行文本(textarea)</option>
                        <option value="select" {if isset($rowData['html']) && $rowData['html']=='select'}selected{/if} >下拉框(select)</option>
                        <option value="radio" {if isset($rowData['html']) && $rowData['html']=='radio'}selected{/if} >单选框(radio)</option>
                        <option value="checkbox" {if isset($rowData['html']) && $rowData['html']=='checkbox'}selected{/if} >多选框(checkbox)</option>
                        <option value="hidden" {if isset($rowData['html']) && $rowData['html']=='hidden'}selected{/if} >隐藏域(hidden)</option>
                        <option value="date" {if isset($rowData['html']) && $rowData['html']=='date'}selected{/if} >日期选择</option>
                        <option value="time" {if isset($rowData['html']) && $rowData['html']=='time'}selected{/if} >时间选择</option>
                        <option value="thumb" {if isset($rowData['html']) && $rowData['html']=='thumb'}selected{/if} >缩略图上传</option>
                        <!--<option value="file" {if isset($rowData['html']) && $rowData['html']=='file'}selected{/if} >文件上传</option>-->
                        <!--<option value="editor" {if isset($rowData['html']) && $rowData['html']=='editor'}selected{/if} >网页编辑器</option>-->
                    </select>
                </td>
            </tr>
            <tr>
                <td class="tl">
                    <span> 默认值</span>
                </td>
                <td>
                    <textarea class="long" name="default_value" style="min-height:80px;" >{if isset($rowData['default_value'])}{$rowData['default_value']}{/if}</textarea>
                </td>
            </tr>
            <tr id="tr_wh" {if isset($rowData['html']) && !in_array($rowData['html'],array("thumb","editor"))}style="display:none;"{/if} >
                <td class="tl">
                    <span> 默认宽高</span>
                </td>
                <td>
                    <input type="text" name="width" value='{if isset($rowData['width'])}{$rowData['width']}{/if}'> X  <input type="text" name="height" value='{if isset($rowData['height'])}{$rowData['height']}{/if}'>
                </td>
            </tr>
            <tr id="tr_option" {if isset($rowData['html']) && !in_array($rowData['html'],array("select","radio","checkbox"))}style="display:none;"{/if} >
                <td class="tl">
                    <span> 选项值</span>
                </td>
                <td>
                    <textarea class="long" name="option_value" style="min-height:80px;" >{if isset($rowData['option_value'])}{$rowData['option_value']}{/if}</textarea>一行一个 选项值|选项名称* 注意*为结尾标志符
                </td>
            </tr>
            <tr>
                <td class="tl">
                    <span>输入限制</span>
                </td>
                <td>
                    <div>
                        <div>
                            <input class="long" type="text" name="input_limit" value='{if isset($rowData['input_limit'])}{$rowData['input_limit']}{/if}' size="40">
                            <select onchange="changeLimit(this)">
                                <option value="">无限制</option>
                                <option value="notnull" >不能为空</option>
                                <option value="numeric" >限数字</option>
                                <option value="letter" >限字母</option>
                                <option value="nl" >限数字和字母</option>
                            </select>
                        </div>
                        <div>
                            可以直接书写兼容js和php的正则表达式<br />
                        </div>
                    </div>
                </td>
            </tr>
            <tr id="tr_addition" >
                <td class="tl">
                    <span>附加内容</span>
                </td>
                <td>
                    <input class="long" type="text" name="addition" value='{if isset($rowData['addition'])}{$rowData['addition']}{/if}'>可以添加表单属性、JS事件或CSS样式 如果有单引号请加 \
                </td>
            </tr>
            <tr>
                <td class="tl">
                    <span><strong>* </strong>后端显示</span>
                </td>
                <td>
                    <p class="article-status">
                        <input name="backend_show" type="radio" value="1" {if isset($rowData['backend_show']) && $rowData['backend_show']=='1'}checked{/if} >是
                        <input name="backend_show" type="radio" value="0" {if isset($rowData['backend_show']) && $rowData['backend_show']=='0'}checked{/if} >否
                    </p>
                </td>
            </tr>
            <tr>
                <td class="tl">
                    <span><strong>* </strong>前端显示</span>
                </td>
                <td>
                    <p class="article-status">
                        <input name="use_show" type="radio" value="1" {if isset($rowData['use_show']) && $rowData['use_show']=='1'}checked{/if} >是
                        <input name="use_show" type="radio" value="0" {if isset($rowData['use_show']) && $rowData['use_show']=='0'}checked{/if} >否
                    </p>
                </td>
            </tr>
            </tbody>
        </table>
        <div class="ltcms-button">
            <button class="btns submit ajaxBtn" type="button" data-submit-url="{LTCMS_ROUTE_PREFIX}/fields" data-form=".ajaxForm" data-location-url="{LTCMS_ROUTE_PREFIX}/fields?moduleId={$request['moduleId']}" data-close="5" >保存并提交</button>
            <button class="btns cancel">取消并返回</button>
        </div>
    </form>
</div>
<script>
    /**
     * 输入限制
     * @param obj
     */
    function changeLimit(obj) {
        var val=$(obj).val();
        if(val == 'notnull') {
            $("input[name='input_limit']").val("1");
        } else if(val == 'numeric') {
            $("input[name='input_limit']").val("[0-9]{1,}");
        } else if(val == 'letter') {
            $("input[name='input_limit']").val("[A-Za-z]{1,}");
        } else if(val == 'nl') {
            $("input[name='input_limit']").val("[A-Za-z0-9]{1,}");
        }else {
            $("input[name='input_limit']").val("");
        }
    }

    /**
     * 修改字段属性
     * @param obj
     */
    function changeType(obj) {
        var val=$(obj).val();
        if(val == 'varchar') {
            $("#tr_length").css("display","");
            $("input[name='length']").val(255);
        } else if(val == 'int') {
            $("#tr_length").css("display","");
            $("input[name='length']").val(10);
        } else if(val == 'float') {
            $("#tr_length").css("display","none");
            $("input[name='length']").val("");
        } else if(val == 'text') {
            $("#tr_length").css("display","none");
            $("input[name='length']").val("");
        }
    }

    /**
     * 修改表单类型
     * @param obj
     */
    function changeHtml(obj) {
        var val=$(obj).val();
        if(val == 'select' || val == 'radio' || val == 'checkbox') {
            $("#tr_option").css("display","");
            $("#tr_wh").css("display","none");
        } else if(val == 'thumb' || val == 'editor') {
            $("#tr_option").css("display","none");
            $("#tr_wh").css("display","");
            if(val == 'editor') {
                $("input[name='width']").val("600");
                $("input[name='height']").val("300");
            }
        } else {
            $("#tr_option").css("display","none");
            $("#tr_wh").css("display","none");
        }

        if(val == 'text') {
            $("input[name='addition']").val('size="30"');
        } else if(val == 'textarea') {
            $("input[name='addition']").val('rows="5" cols="80"');
        } else {
            $("input[name='addition']").val('');
        }
    }
</script>
<script src="__ADMIN_STATIC__/js/addContent.js?random={extendSetting('random')}"></script>
{include 'admin/layout/footer'}